package cj.web.lkg.dao;

import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;

@DAO
public interface AnswersDAO {
	
	//列表问
	@SQL("SELECT id,carouselImage,userId,msg,pvNum,praiseNum,commentsNum,forwardNum,collectNum,createAt FROM Feedback WHERE deleteFlag=1 and status=0 and createAt>:1  ORDER BY stickAT DESC,createAt DESC ")
    List<Map> queryPull(String createAt,int start,int length);
	
	//问size
	@SQL("SELECT count(1) FROM Feedback WHERE deleteFlag=1 and status=0 and createAt>:1 ")
    int queryPullSize(String createAt);
	
	//列表问
	@SQL("SELECT id,carouselImage,userId,msg,pvNum,praiseNum,commentsNum,forwardNum,collectNum,createAt FROM Feedback WHERE deleteFlag=1 and status=0 and createAt<:1 ORDER BY stickAT DESC,createAt DESC LIMIT :2,:3 ")
    List<Map> queryPush(String createAt,int start,int length);
	
	//问size
	@SQL("SELECT count(1) FROM Feedback WHERE deleteFlag=1 and status=0 and createAt<:1")
    int queryPushSize(String createAt);

	//列表问
	@SQL("SELECT id,carouselImage,userId,msg,pvNum,praiseNum,commentsNum,forwardNum,collectNum,createAt FROM Feedback WHERE deleteFlag=1 and status=0 ORDER BY stickAT DESC,createAt DESC LIMIT :1,:2 ")
    List<Map> query(int start,int length);
	
	//问size
	@SQL("SELECT count(1) FROM Feedback WHERE deleteFlag=1 and status=0 ")
    int querySize();
	
	//列表问
	@SQL("SELECT id,carouselImage,userId,msg,pvNum,praiseNum,commentsNum,forwardNum,collectNum,createAt FROM Feedback WHERE deleteFlag=1 and status=0 and id=:1 ")
    List<Map> queryDetailById(int id);
	
	//-------------------
	//查询答Pull-------------------
	@SQL("select id,feedbackId,contents,reply,replyUserId,replyName,createAt,praiseNum from FeedbackReply where deleteFlag=1 and feedbackId=:1 ORDER BY id DESC LIMIT :2,:3 ")
	List<Map> queryAnsById(int feedbackId,int start,int length);
	//查询答
	@SQL("select count(1) from FeedbackReply where deleteFlag=1 and feedbackId=:1")
	int queryAnsByIdSize(int feedbackId);
	
	
	@SQL("select id,feedbackId,contents,reply,replyUserId,replyName,createAt,praiseNum from FeedbackReply where deleteFlag=1 and createAt>:4 and feedbackId=:1 #if(:5==0){ ORDER BY id DESC } #if(:5==1){ ORDER BY praiseNum DESC } ")
	List<Map> queryAnsPullById(int feedbackId,int start,int length,String createAt,int order);
	//查询答
	@SQL("select count(1) from FeedbackReply where deleteFlag=1 and feedbackId=:1 and createAt>:2 ")
	int queryAnsPullByIdSize(int feedbackId,String createAt);
	
	
	//查询答Push
	@SQL("select id,feedbackId,contents,reply,replyUserId,replyName,createAt,praiseNum from FeedbackReply where deleteFlag=1 and createAt<:4 and feedbackId=:1 #if(:5==0){ ORDER BY id DESC } #if(:5==1){ ORDER BY praiseNum DESC } LIMIT :2,:3 ")
	List<Map> queryAnsPushById(int feedbackId,int start,int length,String createAt,int order);
	//查询答
	@SQL("select count(1) from FeedbackReply where deleteFlag=1 and feedbackId=:1 and createAt<:2")
	int queryAnsPushByIdSize(int feedbackId,String createAt);
	
	
	//提问
	@SQL("INSERT INTO Feedback (userId,carouselImage,title,msg,status,pvNum,praiseNum,commentsNum,forwardNum,collectNum,deleteFlag,createUser,createAt) VALUES (:t.userId,:t.carouselImage,:t.title,:t.msg,0,0,0,0,0,0,1,:t.createUser,now())")
	void createQue(@SQLParam("t") Map rep);
	//回答
	@SQL("INSERT INTO FeedbackReply (feedbackId,userId,contents,isAnonymous,releaseState,reply,replyUserId,replyName,praiseNum,deleteFlag,createUser,createAt) VALUES (:t.feedbackId,:t.userId,:t.contents,:t.isAnonymous,0,:t.reply,:t.replyUserId,:t.replyName,0,1,:t.createUser,now())")
	void createAns(@SQLParam("t") Map rep);
	
	//问点赞------------------
	@SQL("INSERT INTO FeedbackPraises (feedbackId,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.feedbackId,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createQuePraise(@SQLParam("t") Map rep);
	//问size
	@SQL("SELECT count(1) FROM FeedbackPraises WHERE deleteFlag=1 AND feedbackId=:1 AND userId=:2 ")
    int queryQuePraiseSize(int feedbackId,int userId);
	//删除回点赞
	@SQL("DELETE FROM FeedbackPraises WHERE deleteFlag=1 AND feedbackId=:1 AND userId=:2")
	void delQuePraise(int feedbackId,int userId);
	//修改点赞数
	@SQL("update Feedback set praiseNum=praiseNum+1 where id=:1")
    void addFeedbackById(int id);
	//修改点赞数
	@SQL("update Feedback set praiseNum=praiseNum-1 where id=:1")
    void subFeedbackById(int id);
	
	//答点赞------------------
	@SQL("INSERT INTO FeedbackReplyPraises (feedbackId,feedbackReplyId,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.feedbackId,:t.feedbackReplyId,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createAnsPraise(@SQLParam("t") Map rep);
	//答size
	@SQL("SELECT count(1) FROM FeedbackReplyPraises WHERE deleteFlag=1 AND feedbackId=:1 AND feedbackReplyId=:2 AND userId=:3 ")
    int queryAnsPraiseSize(int feedbackId,int feedbackReplyId,int userId);
	//删除答点赞
	@SQL("DELETE FROM FeedbackReplyPraises WHERE deleteFlag=1 AND feedbackId=:1 AND feedbackReplyId=:2 AND userId=:3 ")
	void delAnsPraise(int feedbackId,int feedbackReplyId,int userId);
	//修改点赞数
	@SQL("update FeedbackReply set praiseNum=praiseNum+1 where id=:1")
    void addFeedbackReplyById(int id);
	//修改点赞数
	@SQL("update FeedbackReply set praiseNum=praiseNum-1 where id=:1")
    void subFeedbackReplyById(int id);
	
	//答PV量------------------
	@SQL("INSERT INTO FeedbackPV (feedbackId,userId,userName,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.feedbackId,:t.userId,:t.userName,1,:t.createUser,now(),:t.updateUser,now())")
	void createFeedbackPV(@SQLParam("t") Map rep);
	//查询浏览
	@SQL("SELECT count(1) FROM FeedbackPV WHERE deleteFlag=1 AND feedbackId=:1 AND userId=:2 ")
    int queryFeedbackPVSize(int feedbackId,int userId);
	//修改新闻浏览数
	@SQL("update Feedback set pvNum=pvNum+1 where id=:1")
    void addFeedbackPVById(int id);
}